package com.tedu.egmvc.controller;

import com.tedu.egmvc.mapper.AddressMapper;
import com.tedu.egmvc.pojo.dto.AddressDTO;
import com.tedu.egmvc.pojo.dto.AddressUpdateDTO;
import com.tedu.egmvc.pojo.entity.Address;
import com.tedu.egmvc.pojo.vo.AddressVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/address")
@RestController
public class AddressController {
    @Autowired
    private AddressMapper addressmapper;
    @RequestMapping("/insert")
    public String insert(AddressDTO addressDTO){
        Address address = new Address();
        BeanUtils.copyProperties(addressDTO, address);
        System.out.println(address);
        int insert = addressmapper.insert(address);
        return insert>0?"添加成功":"添加失败";
    }

    @RequestMapping("/select")
    public List<AddressVO> select(){
        List<AddressVO> select = addressmapper.select();
        return select;
    }
    @RequestMapping("/delete")
    public String delete(Integer id){
        int delete = addressmapper.delete(id);
        return delete>0?"删除成功":"删除失败";
    }
    @RequestMapping("/update")
    public String update(AddressUpdateDTO addressUpdateDTO){
        Address address = new Address();
        BeanUtils.copyProperties(addressUpdateDTO,address);
        int update = addressmapper.update(address);

        return update>0?"修改成功":"修改失败";
    }
}
